package org.agiletestplus.client.ui;

import org.agiletestplus.client.objects.Configuration;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class EditConfigurationPanel extends FlexTable {
  Configuration configuration = null;
  TextBox nameTextBox = new TextBox();
  TextBox descriptionTextBox = new TextBox();

  public EditConfigurationPanel() {
    populateUI();
  }
  
  public EditConfigurationPanel(Configuration configuration) {
    apply(configuration);
    populateUI();
  }
  
  public void apply(Configuration configuration) {
    this.configuration = configuration;
    nameTextBox.setText(configuration.getName());
    descriptionTextBox.setText(configuration.getDescription()); 
  }
  
  public void update() {
    configuration.setName(nameTextBox.getText());
    configuration.setDescription(descriptionTextBox.getText());
  }
  
  public void populateUI() {
    // build ui
    int row = 0;
    setWidget(row, 0, new Label("Name"));
    setWidget(row, 1, nameTextBox);
    setWidget(++row, 0, new Label("Description"));
    setWidget(row, 1, descriptionTextBox);
  }
}
